package com.cs.framework.jdbc.mybatis3.session.module;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import com.cs.framework.core.context.Module;
import com.cs.framework.jdbc.common.session.CSSessionFactory;
import com.cs.framework.jdbc.common.util.DBConstant;
import com.cs.framework.jdbc.mybatis3.session.BaseSelectSessionFactory;

/**
 * 模块使用的MyBatis工厂
 * 
 * @author hedongzhou
 * 
 */
public class ModuleSessionFactory extends BaseSelectSessionFactory implements CSSessionFactory,
		ApplicationContextAware, InitializingBean {

	/**
	 * 模块上下文
	 */
	protected Module module;

	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		module = (Module) applicationContext;
	}

	public void afterPropertiesSet() throws Exception {
		buildSessionFactory();
	}

	/**
	 * 构建工厂
	 */
	public void buildSessionFactory() throws Exception {
		build(module.getModuleId(), module.getPackageUrl() + DBConstant.MODULE_MYBATIS_CUSTOM_CONF);
	}

}
